import {InvAuditStockInDetail} from '../../../../api/inv/invShouGong/dto'
import { ElTable } from 'element-plus';
import { isNull } from '/@/utils';
import { msg } from '/@/utils'

export const useTableFun = (detailList: InvAuditStockInDetail[]) => {
  const bloodInfoRef = ref(ElTable)
  const delInfo = () => {
    let selection = bloodInfoRef.value.getSelectionRows()
    if(isNull(selection)) {
      msg.error('请选择要删除的数据')
      return
    }
    // 初始化一个空数组来存储要删除的索引
    const indexesToRemove: number[] = []
    // 遍历 detailList，将与 selection 中的 basBloodProductCode 相同的项的索引记录到 indexesToRemove 数组
    detailList.forEach((item: InvAuditStockInDetail, index: number) => {
      if (selection.some((selectionItem: InvAuditStockInDetail) => selectionItem.basBloodProductCode === item.basBloodProductCode)) {
        indexesToRemove.push(index);
      }
    })
    // 从 detailList 中删除索引对应的项
    indexesToRemove.reverse().forEach(index => {
      detailList.splice(index, 1);
    })
  }



  return {
    bloodInfoRef,
    delInfo
  }
}